﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;

namespace QG.FrontDesk.Core
{
    public class ConfigHelper
    {
        /// <summary>
        /// 获取AppSettings下指定key的value
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetAppSettingsValue(string key)
        {
            var result = ConfigurationManager.AppSettings[key];
            return result == null ? "" : result;
        }
        /// <summary>
        /// 获取section下指定key的value
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetSectionValue(string section, string key)
        {
            IDictionary dic = (IDictionary)ConfigurationManager.GetSection(section);
            var result = dic[key];
            return result == null ? "" : result.ToString();
        }
        /// <summary>
        /// 获取section下所有的key
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static List<string> GetSectionListKey(string section)
        {
            IDictionary dic = (IDictionary)ConfigurationManager.GetSection(section);
            List<string> list = new List<string>();
            foreach (var item in dic.Keys)
            {
                list.Add(item.ToString());
            }
            return list;
        }
    }
}
